#####################################################################
# Figure 2
#####################################################################

rm(list=ls())

library(Hmisc)
library(exactRankTests)
library(ggplot2)
library(reshape2)
library(xtable)
library(stargazer)
library(sensitivitymw)
library(sensitivitymv)
library(lmtest)
library(sandwich)
library(stargazer)
library(msm)

# Read data and prepare basic output
load("~/Dropbox/Crime Brazil/06_replication/001_rematch_crime.Rdata")

########################
# Fine balance plot
########################

# fine balance
d$groups = d$t_ind
d$groups[d$t_ind==0]="Control"
d$groups[d$t_ind==1]="Treated"
table(d$groups)

d_match$groups = d_match$t_ind
d_match$groups[d_match$t_ind==0]="Control"
d_match$groups[d_match$t_ind==1]="Treated"
table(d_match$groups)

# Fine balance before
ggplot(d, aes(x=bairroibge_wave3, fill=groups)) + labs(x="Neighborhood", y="Count") + geom_histogram(binwidth=.5, alpha=.5, position="dodge") + theme_bw() +  scale_fill_manual(name = "Groups",values=c("black", "grey60") ) + scale_y_continuous(breaks=c(0,10,20,30,40,50,60,70,80,90)) + coord_cartesian(ylim=c(0,90)) + theme(legend.key = element_rect(colour = NA)) + theme(text = element_text(size=15))
  theme(text = element_text(size=15))


# Fine balance after
ggplot(d_match, aes(x=bairroibge_wave3, fill=groups)) + labs(x="Neighborhood", y="Count") + geom_histogram(binwidth=.5, alpha=.5, position="dodge") + theme_bw() +  scale_fill_manual(name = "Groups", values=c("black", "grey60") ) + scale_y_continuous(breaks=c(0,10,20,30,40,50,60,70,80,90)) + coord_cartesian(ylim=c(0,90)) + theme(legend.key = element_rect(colour = NA)) + theme(text = element_text(size=15))
